package com.service.impl;

import com.entity.Type;
import com.mapper.TypeMapper;
import com.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TypeServiceImpl implements TypeService {

    @Autowired
    private TypeMapper typeMapper;

    @Override
    public List<Type> getTypeTree() {
        List<Type> data = typeMapper.SelectAllType();
        List<Type> typeList=new ArrayList<>(data);
        for (Type entity : data) {
            for (Type entity2 : data) {
                //如果本级id与数据的父id相同，就说明是子父级关系
                if (entity.getUuid().equals(entity2.getParentId())) {
                    entity.getChilds().add(entity2);
                    typeList.remove(entity2);
                }
            }
        }
        return typeList;
    }

}
